package com.zzzzzz.common.validator;

import java.util.regex.Pattern;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

public class MyValidatorUtils {
	private static final String SIMPLE_EMAIL_REGEX = "[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}";
	
	public static void validateEmail(String email, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty");
		if (!Pattern.matches(SIMPLE_EMAIL_REGEX, email.toUpperCase())) {
			errors.rejectValue("email", "invalid.email", "Email格式非法");
		}
	}
}
